//
//  MNDFinanceRecordViewController.m
//  minidai
//
//  Created by 谭谭伟 on 17/5/21.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDFinanceRecordViewController.h"
#import "MNDFinanceTenderModel.h"
#import "MNDFinanceRecordCell.h"
@interface MNDFinanceRecordViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *addTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *wayLabel;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (strong, nonatomic) NSMutableArray *tenderAyyayM;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *topTipLabel;
// -------- tabview距离下面间距 --------
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMarginConstraint;


@end

@implementation MNDFinanceRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableFooterView = [[UIView alloc]init];
    // Do any additional setup after loading the view.
    self.tableView.estimatedRowHeight = 40;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (kDevice_iPad) {
        self.bottomMarginConstraint.constant = 114;
    }else {
        if (kScreenWidth > 375) {
            self.bottomMarginConstraint.constant = 114;
        }else {
            self.bottomMarginConstraint.constant = 50;
        }
        
    }
}
- (NSMutableArray *)tenderAyyayM {
    if (!_tenderAyyayM) {
        _tenderAyyayM = [NSMutableArray array];
    }
    return _tenderAyyayM;
}

-(void)setTender:(NSArray *)tender {
    _tender = tender;
    //投标记录数据
    for (NSDictionary *dict in tender) {
        MNDFinanceTenderModel *tenderModel = [MNDFinanceTenderModel yy_modelWithDictionary:dict];
        [self.tenderAyyayM addObject:tenderModel];
    }
    if (self.tenderAyyayM.count > 0) {
        //        [self creatMaskView];
        //        self.maskView.hidden = YES;
    }else {
        [self creatMaskView];
        //        self.maskView.hidden = NO;
    }
    [self.tableView reloadData];
}


#pragma mark UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tenderAyyayM.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MNDFinanceTenderModel *tenderModel = self.tenderAyyayM[indexPath.row];
    MNDFinanceRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MNDFinanceRecordCell"];
    cell.userNameLabel.text = tenderModel.user_name;
    cell.moneyLabel.text = tenderModel.money;
    cell.wayLabel.text = tenderModel.way;
    cell.addTimeLabel.text = tenderModel.add_time;
    return cell;
}

- (void)creatMaskView {
    UIView *maskView = [[UIView alloc]initWithFrame:self.view.bounds];
    maskView.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
//    [self.view insertSubview:maskView aboveSubview:self.tableView];
    [self.tableView addSubview:maskView];
    UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"financen_detail_data_empty"]];
    [maskView addSubview:imgV];
    imgV.layer.cornerRadius = imgV.bounds.size.height*0.5;
    imgV.clipsToBounds = YES;
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(maskView);
        make.centerY.equalTo(maskView).mas_offset(-80);
    }];
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (kDevice_iPad) {
        return;
    }
    CGFloat distance = scrollView.contentOffset.y;
    if (distance < -10) {
        NSLog(@"------%f------",distance);
        self.topTipLabel.alpha = (-distance-10)/30;
        NSLog(@"------透明度%f------",self.topTipLabel.alpha);
    }
    if (distance == 0) {
        self.topTipLabel.alpha = 0;
    }
    if (distance < -40) {
        self.topTipLabel.text = @"释放回到出借详情";
    }else {
        self.topTipLabel.text = @"下拉回到出借详情";
    }
}

//- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
//    if (self.delegate && [self.delegate respondsToSelector:@selector(recordBottomViewDidEndDragging:)]) {
//        
//        [self.delegate recordBottomViewDidEndDragging:self.tableView];
//    }
//}

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
    if (self.delegate && [self.delegate respondsToSelector:@selector(recordBottomViewDidEndDragging:)]) {
        
        [self.delegate recordBottomViewDidEndDragging:self.tableView];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
